package it.webrules.deploymanager.core;

import it.webrules.xsd.dmc.config.v1.ExecuteCommand;
import it.webrules.xsd.dmc.config.v1.SendEmail;

/**
 * 
 * 
 * 
 * @author dometec
 *
 */

public class HookManager {

	public void execCommand(Object actchoosen) throws HookException {
		ExecuteCommand commnad = (ExecuteCommand) actchoosen;

		try {

			String cmd = commnad.getValue().trim();
			Integer checkexitcode = commnad.getCheckexitcode();
			boolean printoutput = commnad.isPrintoutput();
			boolean failsilently = commnad.isFailsilently();

			it.webrules.deploymanager.core.utils.System.execute(cmd, checkexitcode, printoutput, failsilently);

		} catch (Exception e) {
			throw new HookException("Hook failed!", e);
		}
	}

	public void sendmail(MailService mailService, Object actchoosen) {
		SendEmail sendEmail = (SendEmail) actchoosen;

		String mailAddressTo = sendEmail.getTo();
		String mailSubject = sendEmail.getSubject();
		String content = sendEmail.getValue();

		mailService.send(mailAddressTo, mailSubject, content);

	}

}
